DWCLODDL ;CLD/JOLLIS - Output file as DDL;9:05 PM 19 Sep 2011
 ;;0.1;FileMan Web Tools;;19 Sep 2011

FILEDDL(FILENUM,OUTPUT)
 O OUTPUT
 U OUTPUT
 D FILE^DWCLWALK(FILENUM,"DDLFILE^DWCLODDL","DDLEOF^DWCLODDL","DDLFIELD^DWCLODDL","DDLFLEOF^DWCLODDL")
 U $P
 Q


DDLFILE(FILENUM)
 I $$ISSUB^DWDIQ(FILENUM)=0 D
 .W "CREATE FILE ",FILENUM," LABEL """,$$FILENAME^DWDIQ(FILENUM),""" CONTAINING "
 I $$ISSUB^DWDIQ(FILENUM)=1 D
 .W " OF ",FILENUM," CONTAINING "
 W !,"("
 Q

DDLEOF(FILENUM)
 I $$ISSUB^DWDIQ(FILENUM)=0 W ") GLOBAL=""",$$ROOT^DWDIQ(FILENUM),""""
 I $$ISSUB^DWDIQ(FILENUM)=1 W ")"
 Q

DDLFIELD(FILENUM,FLDNUM)
 W FLDNUM," LABEL """,$$FLDNAME^DWDIQ(FILENUM,FLDNUM),""""
 I $$FLDREQD^DWDIQ(FILENUM,FLDNUM)="Yes" W " NOT NULL"
 I $$PRTLEN^DWDIQ(FILENUM,FLDNUM)'="Undefined" W " PRINTLEN ",$$PRTLEN^DWDIQ(FILENUM,FLDNUM)
 W " AS ",$$DDLTYPE^DWDIQ(FILENUM,FLDNUM)
 I $$DDLTYPE^DWDIQ(FILENUM,FLDNUM)="POINTER" D
 .N LG,PFN S PFN=$$POINTER^DWDIQ(FILENUM,FLDNUM,.LG)
 .W " TO ",PFN
 .I LG="Yes" W " WITH LAYGO"
 I $$DDLTYPE^DWDIQ(FILENUM,FLDNUM)="SET" D
 .N SOC,CNT,I,CURKEY S CNT=$$CODES^DWDIQ(FILENUM,FLDNUM,.SOC),CURKEY=""
 .W " [ "
 .F I=0:1 S CURKEY=$O(SOC(CURKEY)) Q:CURKEY=""  D
 ..W """",CURKEY,"""=""",SOC(CURKEY),""" "
 .W "]"
 N XREFS,I,CNT
 S CNT=$$FLDXREFS^DWDIQ(FILENUM,FLDNUM,.XREFS)
 I CNT'=0 D
 .W " XREF [ "
 .F I=1:1:CNT D
 ..W """",XREFS(I),""" "
 .W "]"
 Q

DDLFLEOF(FILENUM,FLDNUM)
 I ^DWCLLAST(FILENUM)=0 W ",",! E  W !
 Q